﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Workbench.Models
{
    public class ProjectItemModel : PersistableModel
    {
        public string Name;

        public long ParentDirectoryId;
        public ProjectDirectoryModel ParentDirectory;
    }

    [DebuggerDisplay("Directory: Name={Name}")]
    public class ProjectDirectoryModel : ProjectItemModel, IEquatable<ProjectDirectoryModel>
    {
        public List<ProjectItemModel> Children = new List<ProjectItemModel>();

        public List<ProjectFileModel> GetFiles()
        {
            var result = new List<ProjectFileModel>();
            var childFiles = new List<ProjectFileModel>();
            foreach (var child in Children)
            {
                var childDirectory = child as ProjectDirectoryModel;
                if (childDirectory != null)
                {
                    result.AddRange(childDirectory.GetFiles());
                }
                else
                {
                    var childFile = child as ProjectFileModel;
                    if (childFile != null) result.Add(childFile);
                }
            }
            result.AddRange(childFiles);
            return result;
        }

        public List<ProjectFileModel> GetContextIncludedFiles()
        {
            return GetFiles().Where(x => x.ContextIncluded).ToList();
        }

        public bool Equals(ProjectDirectoryModel other)
        {
            if (other == null) return false;
            return RowId == other.RowId;
        }
    }

    [DebuggerDisplay("File: Name={Name}")]
    public class ProjectFileModel : ProjectItemModel, IEquatable<ProjectFileModel>
    {
        public bool Equals(ProjectFileModel other)
        {
            if (other == null) return false;
            return RowId == other.RowId;
        }

        public FileContentModel FileContent;
        public long FileContentId;

        public bool ContextIncluded;
    }

    public class FileContentModel : PersistableModel, IEquatable<FileContentModel>
    {
        public string Content;

        public bool Equals(FileContentModel other)
        {
            if (other == null) return false;
            return this.RowId == other.RowId;
        }
    }

    public class FileStatisticsModel : PersistableModel, IEquatable<FileContentModel>
    {
        public long FileId;
        public ProjectFileModel File;

        public long Paragraphs;
        public long Sentences;
        public long TextLengthInRunningWords;
        public long DifferentForms;
        public long MaximumNumberOfSentencesInParagraph;
        public long MaximumNumberOfWordsInSentence;

        public double AverageLengthOfSentenceInWords;
        public double AverageLengthOfParagraphInWords;
        public double AverageLengthOfParagraphInSentences;

        public bool Equals(FileContentModel other)
        {
            if (other == null) return false;
            return this.RowId == other.RowId;
        }
    }
}